import type { Course } from '../../types';

export const toMinutes = (hhmm: string) => {
  const [h, m] = hhmm.split(':').map(Number);
  return h * 60 + m;
};

export const overlap = (
  a: { dayOfWeek: number; start: string; end: string },
  b: { dayOfWeek: number; start: string; end: string }
) => a.dayOfWeek === b.dayOfWeek && Math.max(toMinutes(a.start), toMinutes(b.start)) < Math.min(toMinutes(a.end), toMinutes(b.end));

export const hasConflict = (mine: Course[], candidate: Course) =>
  mine.some(m => m.timeSlots.some(a => candidate.timeSlots.some(b => overlap(a, b))));


